<?php

use Lg\View\JsBlock;
use Lg\View\Asset;
?>

<?php echo get_header(); ?>
<form class="form-horizontal" action="" method="post">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <i class="fa fa-list-ul"></i> 可用插件列表
                </div>
                <div class="card-block">
                    <div class="p-b-1">
                        <a href="<?php echo url_for('/plugins/plugins.php?action=add'); ?>" class="btn btn-success btn-md"><i class="fa fa-search"></i> 重新扫描</a>
                    </div>
                    <table class="table table-hover table-outline mb-0 hidden-sm-down">
                        <thead class="thead-default">
                            <tr>
                                <th width="10%">.</th>
                                <th>插件名称</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $module_list = [];
                            $system_modules = lg_system_get_all_modules();
                            if (($handle = opendir(ADMIN_PATH))) {
                                while (false !== ($entry = readdir($handle))) {
                                    if ($entry != "." && $entry != ".." && is_dir(ADMIN_PATH . '/' . $entry)) {
                                        $module_spec = ADMIN_PATH . '/' . $entry . '/config/spec.php';
                                        if (is_file($module_spec)) {
                                            $module_info = include $module_spec;
                                            if (is_array($module_info) && array_has($module_info, 'module_name') && !in_array($module_info['module_name'], $system_modules)) {
                                                $module_list[] = $module_info;
                                            }
                                        }
                                    }
                                }
                                closedir($handle);
                            }
                            $i = 1;
                            foreach ($module_list as $module) {
                                ?>
                                <tr>
                                    <td width="10px"><?php echo $i++; ?></td>
                                    <td><b><?php echo $module['displayname']; ?></b>
                                    </td>
                                    <td><?php echo $module['sort_order']; ?></td>
                                    <td width="20%">                                        
                                        <a href="<?php echo url_for('/plugins/plugins.php', ['action' => 'install', 'module_name' => $module['module_name'] ]); ?>"    >
                                            <i class="fa fa-plus-circle"></i> 安装</a>
                                    </td>
                                </tr>
<?php } ?>

                        </tbody>
                    </table>
                </div>
            </div>

        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->


</form>

<?php echo get_footer(); ?>